import { deepCopy } from '../utils/toolsHelper';

/*
 * @Author: MrDotYan 2564217790@qq.com
 * @Date: 2024-09-11 17:02:42
 * @LastEditors: MrDotYan 2564217790@qq.com
 * @LastEditTime: 2024-09-12 11:38:18
 * @FilePath: /EqDataProcessWeb/src/views/dataProcess/electricalEngineering/components/stack.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
export class Stack<T> {
  private items: T[] = [];

  // 添加元素到堆栈
  push(item: T): void {
    this.items.push(deepCopy(item));
  }

  // 从堆栈中移除并返回最后添加的元素
  pop(): T | undefined {
    return this.items.pop();
  }

  // 返回堆栈顶部的元素但不移除它
  peek(): T | undefined {
    return this.items[this.items.length - 1];
  }

  // 检查堆栈是否为空
  isEmpty(): boolean {
    return this.items.length === 0;
  }

  // 返回堆栈的大小
  size(): number {
    return this.items.length;
  }
}
